package org.algorithm.biubiu.wheel_1.数组.三月.第四周;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zhx
 * @date 2022-03-21 星期一18:26
 *
 * url: https://leetcode-cn.com/problems/pascals-triangle-ii/
 */
public class 杨辉三角II {

    public static void main(String[] args) {
        System.out.println(getRow(3));
    }


    /**
     * 输入: rowIndex = 3
     * 输出: [1,3,3,1]
     *
     * 输入: rowIndex = 0
     * 输出: [1]
     *
     *
     * 输入: rowIndex = 1
     * 输出: [1,1]
     */
    public static List<Integer> getRow(int rowIndex) {
        List<List<Integer>> all = new ArrayList(rowIndex);
        if(rowIndex==0){
            return Arrays.asList(1);
        }
        all.add(Arrays.asList(1));
        for(int i = 1; i<=rowIndex;i++){
            List<Integer> tmp = new ArrayList();
            for(int j=0;j<=i;j++){
                System.out.print(all.size());
                tmp.add(sum(all.get(i-1),j));
            }
            all.add(tmp);
        }
        return all.get(rowIndex);
    }

    public static int sum(List<Integer> list ,int index){
        if(index==0) return 1;
        if(index==list.size()) return 1;
        return list.get(index-1)+list.get(index);
    }

}
